package services

import (
	"context"
	"encoding/json"
	"errors"
	"fmt"
	"net/http"
)

// GetUserInfoRequest 封装请求调用
func GetUserInfoRequest(_ context.Context, request *http.Request, r interface{}) error {
	userRequest := r.(UserRequest)
	request.URL.Path = request.URL.Path + "/user/" + fmt.Sprintf("%d", userRequest.Uid)
	return nil
}

// GetUserInfoResponse 封装返回
func GetUserInfoResponse(_ context.Context, res *http.Response) (response interface{}, err error) {
	if res.StatusCode > 400 {
		return nil, errors.New("on data")
	}
	var userResponse UserResponse
	err = json.NewDecoder(res.Body).Decode(&userResponse)
	if err != nil {
		return nil, err
	}
	return userResponse, nil
}
